using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sbMembership.Library.Presenters;
using sbMembership.Library.Presenters.ViewInterfaces;

namespace sbMembership.Web.Views
{

    public partial class ListUsersView : System.Web.UI.UserControl, IListUsersView
    {
        ListUsersPresenter presenter;

        public void AttachPresenter(ListUsersPresenter presenter)
        {
            this.presenter = presenter;
        }

        public string Message
        {
            set { lblMessage.Text = value; }
        }

        public MembershipUserCollection Users
        {
            set
            {
                gvMembers.DataSource = value;
                gvMembers.DataBind();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            presenter.LaunchAddUser();
        }
        protected void gvMembers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int rowID = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow gr = gvMembers.Rows[rowID];
                string user = ((LinkButton)gr.Cells[0].Controls[0]).Text;
                presenter.DeleteUser(user);
            }
            if (e.CommandName == "MODIFYROLES")
            {
                int rowID = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow gr = gvMembers.Rows[rowID];
                string user = ((LinkButton)gr.Cells[0].Controls[0]).Text;
                presenter.LaunchAssignRoleToUser(user);
            }
            if (e.CommandName == "Select")
            {
                int rowID = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow gr = gvMembers.Rows[rowID];
                string user = ((LinkButton)gr.Cells[0].Controls[0]).Text;
                presenter.LaunchEditUser(user);
            }
        }

        protected void gvMembers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }
    }
}